<template>
  <el-dialog  class="simple-dialog main-page1"
    title="详情"
    :visible.sync="tempVisible"
    width="800px"
    :close-on-press-escape="false"
    :close-on-click-modal="false"
    @close="close"
  >
    <el-descriptions ref="form" class="margin-top" :column="1" size="small" border>
      <el-descriptions-item label="姓名">{{ tempData.name}}</el-descriptions-item>
      <el-descriptions-item label="电话">{{ tempData.phone}}</el-descriptions-item>
      <el-descriptions-item label="身份证号">{{ tempData.idcard}}</el-descriptions-item>
      <el-descriptions-item label="性别">{{ tempData.sex}}</el-descriptions-item>
      <el-descriptions-item label="年龄">{{ tempData.age}}</el-descriptions-item>
      <el-descriptions-item label="生日">{{ tempData.birthday}}</el-descriptions-item>
      <el-descriptions-item label="有无癌症史">
        <el-tag v-if="tempData.isCancer === 0">无</el-tag>
        <el-tag type="danger" v-if="tempData.isCancer === 1">有</el-tag>  
      </el-descriptions-item>
      <el-descriptions-item label="卡号">{{ tempData.cardNum}}</el-descriptions-item>
      <el-descriptions-item label="激活时间">{{ tempData.activationTime}}</el-descriptions-item>
      <el-descriptions-item label="生效时间">{{ tempData.startTime}}</el-descriptions-item>
      <el-descriptions-item label="到期时间">{{ tempData.endTime}}</el-descriptions-item>
    </el-descriptions>
    <span slot="footer" class="dalog-footer">
      <el-button @click="close">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script> 
  import cardApi from '@/api/system/card'
  import publisherApi from '@/api/system/publisher'
  import customerApi from '@/api/system/customer'
  export default {
    name: 'custDetail',
    data() {
      return {
        tempVisible: false,
        projectLeave:0,
        publisherList:[],
        cardList:[],
        tempData: {
          id: null
        },
        rules: {
          name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
          phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
          idcard: [{ required: true, message: '请输入身份证号', trigger: 'blur' }],
          age: [{ required: true, message: '请输入年龄', trigger: 'blur' }],
          sex: [{ required: true, message: '请选择性别', trigger: 'blur' }],
          publisherId: [{ required: true, message: '请选择发行商', trigger: 'blur' }],
          activationCard: [{ required: true, message: '请选择卡号', trigger: 'blur' }], 
        },
        curUserRole: -1,
        inPulisherId:''
      }
    },
    
    computed: {
      user() {
        return this.$store.state.user
      }
    },
    mounted() {
      this.user.roles.forEach(item => {
      if(item != 1 && item != 2){
        this.curUserRole = 3;
        if( this.user.publisherIds){
          this.inPulisherId = this.user.publisherIds
        }
      }
    })
    },
    methods: {
      showDialog(row){
        this.tempVisible = true;
        this.tempData = row;
      },
      //获取发行商
      getPublisher(){
        publisherApi.getPublisher({inPulisherId: this.inPulisherId}).then(res => {
          this.publisherList = res.data
        })
      },
      getPublisherCard(publisher){
        publisherApi.getPublisher().then(res => {
          this.publisherList = res.data
          this.getCard(publisher)
        })
      },  
      // 选择发行商
      getCard(publisher){
        var curSel = this.publisherList.filter(item => item.name == publisher)[0];
        // this.tempData.publisher = curSel.name; 
        cardApi.getCardByPublisher({publisherId: curSel.id}).then(res => {
          this.cardList = res.data
        })
      },
      // 选择卡号
      changeCard(val){
        var curSel = this.cardList.filter(item => item.cardNum == val)[0];
        this.tempData.endTime = curSel.term;
        this.tempData.cardId = curSel.id;
      },
      close() {
        this.$refs['formName'].clearValidate()
        this.$emit('close')
      },
      saveUpdate(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.tempData.id) {
              customerApi.update(this.tempData).then(res => {
                this.$message.success('更新成功')
                this.close()
                this.$emit('reloadTable',res.data)
              }).catch(() => {})
            } else {
              // if(this.curUserRole > -1){
              //   this.tempData.publisherId = this.user.publisherId;
              // }
              customerApi.save(this.tempData).then(res => {
                this.$message.success('添加成功')
                this.$emit('close');
                this.$emit('reloadTable',res.data)
              }) 
            }
          } else {
            return false
          }
        })
      }
    }
  }
</script>

<style lang="scss">

</style>
